package pers.lan.array;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lan
 * @date 2020/9/24
 */
public class LC_1 {
    public static void main(String[] args) {
        int[] nums = new int[]{2, 7, 11, 15};
        int target = 9;
        System.out.println(Arrays.toString(find(nums, target)));
    }

    private static int[] find(int[] nums, int target) {
        Map<Integer, Integer> valIndexedMap = new HashMap<>(nums.length);
        for (int i = 0; i < nums.length; i++) {
            Integer idx = valIndexedMap.remove(target - nums[i]);
            if (idx != null) {
                return new int[]{idx, i};
            }
            valIndexedMap.put(nums[i], i);
        }
        return null;
    }
}
